/*
 * iadef.h
 *
 *  Created on: 2013/01/31
 *      Author: fit
 */

#ifndef IADEF_H_
#define IADEF_H_

#ifndef NULL
#define NULL 0U
#endif

#define SWAPBYTES_2(v) (\
(0x00FF & v) << 8 | \
(0xFF00 & v) >> 8 )

#define SWAPBYTES_4(v) (\
(0x000000FFU & v) << 24 | \
(0x0000FF00U & v) << 8  | \
(0x00FF0000U & v) >> 8  | \
(0xFF000000U & v) >> 24 )

#if ULONG_MAX == UINT_MAX
#define SWAPBYTES_8(v) (\
(0x00000000000000FFULL & v) << 56 | \
(0x000000000000FF00ULL & v) << 48 | \
(0x0000000000FF0000ULL & v) << 24 | \
(0x00000000FF000000ULL & v) << 8  | \
(0x000000FF00000000ULL & v) >> 8  | \
(0x0000FF0000000000ULL & v) >> 24 | \
(0x00FF000000000000ULL & v) >> 48 | \
(0xFF00000000000000ULL & v) >> 56 )
#else
(0x00000000000000FFUL & v) << 56 | \
(0x000000000000FF00UL & v) << 48 | \
(0x0000000000FF0000UL & v) << 24 | \
(0x00000000FF000000UL & v) << 8  | \
(0x000000FF00000000UL & v) >> 8  | \
(0x0000FF0000000000UL & v) >> 24 | \
(0x00FF000000000000UL & v) >> 48 | \
(0xFF00000000000000UL & v) >> 56 )
#endif

enum req_type
{
	req,
#define req_req
	res,
#define res_req
};

enum cmd_type
{
	set,
#define set_cmd set
	get,
#define get_cmd get
	ann,
#define ann_cmd ann
};

struct CMD_HEAD
{
	unsigned char req;
	unsigned short seq;
	unsigned char cmd;
	unsigned char cnt;
};

struct SET_DATA
{
	unsigned char param;
	unsigned char cnt;
};

#endif /* IADEF_H_ */
